/*change the following directory to wherever the dataset is stored on your computer*/
libname everify "D:\state immigration laws\RESTATREVISION\program files for RESTAT readme";
options nocenter;
options linesize=78;
  
 /*the following data step uses the file "everify.combined" which includes all of the 
stacked CPS extracts to restrict the data to Arizona, code flags for the native born, 
Hispanics, and citizen*/
data test;
set everify.combined;
if gestfips=4;
if country ge 100 and citizen in (4,5) then foreign=1; else foreign=0;
if hispanic=1 then hispdummy=1; else hispdummy=0;
if citizen=5 then noncitizen=1; else noncitizen=0;
if foreign=0 then poptype=1;
else if foreign=1 and noncitizen=0 then poptype=2;
else if foreign=1 and noncitizen=1 then poptype=3;
if hispanic=1 and noncitizen=1 then hispnoncitizen=1;
else hispnoncitizen=0;
weight2=weight/12;
run;

/*the following procedures produce the population totals estimates in Table4.  
The estimaes come from summing the resclaed CPS weights within year for those
flagged as native born,foreign-born naturalized citizen, foreign-born non-citizen,
and Noncitizen Hispanic*/

proc freq;
tables year;
weight weight2;
where poptype=1;
title 'native born';
run; 

proc freq;
tables year;
weight weight2;
where poptype=2;
title 'naturalized citizens';
run; 
proc freq;
tables year;
weight weight2;
where poptype=3;
title 'foreign born noncitizen';
run; 

proc freq;
tables year;
weight weight2;
where hispnoncitizen=1;
title 'hispanicnoncitizen';
run; 

/* the following procedures calculate the observations counts upon which the
population estimaets in TAble 4 are based*/

proc freq;
tables year;
where poptype=1;
title 'native born unweighted count';
run; 

proc freq;
tables year;
where poptype=2;
title 'naturalized citizens unweight count';
run; 
proc freq;
tables year;
where poptype=3;
title 'foreign born noncitizen uneweighted count';
run; 

proc freq;
tables year;
where hispnoncitizen=1;
title 'hispanicnoncitizen unweighted count';
run; 

